package com.eusoft.demo.service.impl;

import com.eusoft.demo.entity.CarUser;
import com.eusoft.demo.entity.User;
import com.eusoft.demo.mapper.CarUserMapper;
import com.eusoft.demo.service.ICarUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 用户车辆 服务实现类
 * </p>
 *
 * @author DevMing
 * @since 2021-08-19
 */
@Service
public class CarUserServiceImpl extends ServiceImpl<CarUserMapper, CarUser> implements ICarUserService {

    @Override
    public HashMap<Object, Object> getUserListByCarAid(Integer CarAid, Integer page, Integer pageRows) {
        if (page == null) {
            page = 1;
        }
        if (pageRows == null) {
            pageRows = 10;
        }
        Integer offset = (page - 1) * pageRows;

        List<User> users = baseMapper.queryUserListPageByCarAid(CarAid, offset, pageRows);
        List<HashMap<Object, Object>> lists = new ArrayList<>();
        for (User user : users) {
            HashMap<Object, Object> userMap = new HashMap<>();
            userMap.put("nickname", user.getNickname());
            userMap.put("phone", user.getPhone());
            userMap.put("stateId", user.getStateId());
            userMap.put("stateName", user.getStateName());
            lists.add(userMap);
        }
        HashMap<Object, Object> map = new HashMap<>();
        map.put("rowsNum", baseMapper.queryUserNumByCarAid(CarAid));
        map.put("list", lists);
        return map;
    }
}
